7.2.1 生成坡向坡度数据
higground = dem >600
slope = terrain(dem,opt ='slope')
aspect = terrain(dem,opt='aspect')
hill = hillShade(slope,aspect)
plot(hill,col= grey(0:100/100),legend =F)
plot(dem,col =ranibow(25,alpha=0.35,add=T)
7.2.2 rayshader构建三维立体地图
library(rayshader)
setwd("E:/环境数据/dem/")
loadzip = tempfile()
download.file("https://tylermw.com/data/dem_01.tif.zip", loadzip)
localtif = raster::raster( "./dem_01.tif")
plot(localtif)
elmat = raster_to_matrix(localtif)
elmat %>%
sphere_shade(texture = "desert") %>%
plot_map()
elmat %>%
sphere_shade(sunangle = 45, texture = "desert") %>%
plot_map()
elmat %>%
sphere_shade(texture = "desert") %>%
add_water(detect_water(elmat), color = "desert") %>%
plot_map()
elmat %>%
sphere_shade(texture = "desert") %>%
add_water(detect_water(elmat), color = "desert") %>%
add_shadow(ray_shade(elmat), 0.5) %>%
plot_map()
elmat %>%
sphere_shade(texture = "desert") %>%
add_water(detect_water(elmat), color = "desert") %>%
add_shadow(ray_shade(elmat), 0.5) %>%
add_shadow(ambient_shade(elmat), 0) %>%
plot_map()
elmat %>%
sphere_shade(texture = "desert") %>%
add_water(detect_water(elmat), color = "desert") %>%
add_shadow(ray_shade(elmat, zscale = 3), 0.5) %>%
add_shadow(ambient_shade(elmat), 0) %>%
plot_3d(elmat, zscale = 10, fov = 0, theta = 135, zoom = 0.75, phi = 45, windowsize = c(1000, 800))
Sys.sleep(0.2)
render_snapshot()
elmat %>%
sphere_shade(texture = "desert") %>%
add_water(detect_water(elmat), color = "desert") %>%
add_shadow(ray_shade(elmat, zscale = 3), 0.5) %>%
add_shadow(ambient_shade(elmat), 0) %>%
plot_3d(elmat, zscale = 10, fov = 0, theta = 135, zoom = 0.75, phi = 45, windowsize = c(1000, 800))
render_camera(fov = 0, theta = 60, zoom = 0.75, phi = 45)
render_scalebar(limits=c(0, 5, 10),label_unit = "km",position = "W", y=50,
scale_length = c(0.33,1))
render_compass(position = "E")
render_snapshot(clear=TRUE)
elmat %>%
sphere_shade(texture = "desert") %>%
add_water(detect_water(elmat), color = "desert") %>%
plot_3d(elmat, zscale = 10, fov = 0, theta = 60, zoom = 0.75, phi = 45, windowsize = c(1000, 800))
render_scalebar(limits=c(0, 5, 10),label_unit = "km",position = "W", y=50,
scale_length = c(0.33,1))
render_compass(position = "E")
Sys.sleep(0.2)
library(rayrender)
render_highquality(samples=200, scale_text_size = 24,clear=TRUE)
montshadow = ray_shade(montereybay, zscale = 50, lambert = FALSE)
montamb = ambient_shade(montereybay, zscale = 50)
montereybay %>%
sphere_shade(zscale = 10, texture = "imhof1") %>%
add_shadow(montshadow, 0.5) %>%
add_shadow(montamb, 0) %>%
plot_3d(montereybay, zscale = 50, fov = 0, theta = -45, phi = 45,
windowsize = c(500, 300), zoom = 0.75,
water = TRUE, waterdepth = 0, wateralpha = 0.5, watercolor = "lightblue",
waterlinecolor = "white", waterlinealpha = 0.5)
Sys.sleep(0.2)
render_snapshot(clear=TRUE)
montereybay %>%
sphere_shade(zscale = 10, texture = "imhof1") %>%
add_shadow(montshadow, 0.5) %>%
add_shadow(montamb, 0) %>%
plot_3d(montereybay, zscale = 50, fov = 0, theta = -45, phi = 45, windowsize = c(1000, 800), zoom = 0.6,
water = TRUE, waterdepth = 0, wateralpha = 0.5, watercolor = "lightblue",
waterlinecolor = "white", waterlinealpha = 0.5, baseshape = "circle")
render_snapshot(clear = TRUE)
montereybay %>%
sphere_shade(zscale = 10, texture = "imhof1") %>%
add_shadow(montshadow, 0.5) %>%
add_shadow(montamb,0) %>%
plot_3d(montereybay, zscale = 50, fov = 0, theta = -100, phi = 30, windowsize = c(1000, 800), zoom = 0.6,
water = TRUE, waterdepth = 0, waterlinecolor = "white", waterlinealpha = 0.5,
wateralpha = 0.5, watercolor = "lightblue")
render_label(montereybay, x = 350, y = 160, z = 1000, zscale = 50,
text = "Moss Landing", textsize = 2, linewidth = 5)
render_label(montereybay, x = 220, y = 70, z = 7000, zscale = 50,
text = "Santa Cruz", textcolor = "darkred", linecolor = "darkred",
textsize = 2, linewidth = 5)
render_label(montereybay, x = 300, y = 270, z = 4000, zscale = 50,
text = "Monterey", dashed = TRUE, textsize = 2, linewidth = 5)
render_label(montereybay, x = 50, y = 270, z = 1000, zscale = 50, textcolor = "white", linecolor = "white",
text = "Monterey Canyon", relativez = FALSE, textsize = 2, linewidth = 5)
library(sf)
montereybay %>%
sphere_shade(texture = "desert") %>%
add_shadow(ray_shade(montereybay,zscale=50)) %>%
plot_3d(montereybay,water=TRUE, windowsize=c(1000,800), watercolor="dodgerblue")
render_camera(theta=-60, phi=60, zoom = 0.85, fov=30)
mont_county_buff = sf::st_simplify(sf::st_buffer(monterey_counties_sf,-0.003), dTolerance=0.001)
render_polygons(mont_county_buff,
extent = attr(montereybay,"extent"), data_column_top = "ALAND",
scale_data = 300/(2.6E9), color="chartreuse4",
parallel=TRUE)
render_highquality(clamp_value=10,sample_method="stratified")
montereybay %>%
sphere_shade(texture = "desert") %>%
add_shadow(ray_shade(montereybay,zscale=50)) %>%
plot_3d(montereybay,water=TRUE, windowsize=c(1000,800), watercolor="dodgerblue")
render_camera(theta=-60, phi=60, zoom = 0.85, fov=30)
moss_landing_coord = c(36.806807, -121.793332)
x_vel_out = -0.001 + rnorm(1000)[1:500]/1000
y_vel_out = rnorm(1000)[1:500]/200
z_out = c(seq(0,2000,length.out = 180), seq(2000,0,length.out=10),
seq(0,2000,length.out = 100), seq(2000,0,length.out=10))
bird_track_lat = list()
bird_track_long = list()
bird_track_lat[[1]] = moss_landing_coord[1]
bird_track_long[[1]] = moss_landing_coord[2]
for(i in 2:500) {
bird_track_lat[[i]] = bird_track_lat[[i-1]] + y_vel_out[i]
bird_track_long[[i]] = bird_track_long[[i-1]] + x_vel_out[i]
}
render_points(extent = attr(montereybay,"extent"),
lat = unlist(bird_track_lat), long = unlist(bird_track_long),
altitude = z_out, zscale=50, color="red")
render_highquality(point_radius = 1,sample_method="stratified")
montereybay %>%
sphere_shade() %>%
add_overlay(height_shade(montereybay),alphalayer = 0.6) %>%
add_shadow(ray_shade(montereybay,zscale=50)) %>%
plot_map()
montereybay %>%
height_shade() %>%
add_overlay(generate_contour_overlay(montereybay)) %>%
add_shadow(ray_shade(montereybay,zscale=50)) %>%
plot_3d(montereybay, zscale = 30, fov = 0, theta = 135, zoom = 0.75, phi = 45, windowsize = c(1000, 800))
setwd("E:/环境数据/dem/")
dem <- raster("./wc2.1_30s_elev.tif")
source("E:/sjdata/code/sdmenm.R")
all <- read.csv("E:/sjdata/F1_SP/Hgya3.csv")[,2:3]
range <- mcp(all) %>% rgeos::gBuffer(width =1)
dems <- mask(crop(dem,range),range)
demms<- projectRaster(dems, crs = CRS("+init=epsg:3857") )
plot(demms)
demmss = raster_to_matrix(demms)
demmss[is.na(demmss)] <- 0
demmss %>%
sphere_shade(texture = "desert") %>%
add_water(detect_water(demmss, min_area = 15,zscale=10), color = "desert") %>%
add_shadow(ambient_shade(demmss), 0) %>%
plot_3d(demmss, zscale = 80, fov = 0, theta = 135, zoom = 0.75, phi = 45, windowsize = c(500, 300))
render_points(extent = attr(dems ,"extent"),
lat = unlist(all$latitude),long = unlist(all$longitude),
altitude = z_out, zscale=20, color="red")
render_water(demmss,zscale=10)
render_camera(fov = 0, theta = 60, zoom = 0.75, phi = 45)
render_scalebar(limits=c(0, 250, 500),label_unit = "km",position = "W", y=50,
scale_length = 1)
render_compass(position = "N",scale_distance =1.1, compass_radius=80)
render_snapshot()
extent(demms)
(demms@extent@ymax - demms@extent@ymin ) /1000
bio1 <- raster("E:/环境数据/wc2.0_30s_bio/wc2.0_bio_30s_01.tif")
bio <- mask(crop(bio1,dems),dems)
plot(bio)
biox<- projectRaster(bio, crs = CRS("+init=epsg:3857") )
plot(demms)
bioxc = raster_to_matrix(biox)
bioxc[is.na(bioxc)] <- 0
landsat_mat_list <- lapply(as.list(landsat), function(x){t(raster_to_matrix(x)/255)})
landsat_mat_list[[4]] <- t(raster_to_matrix(raster(nrows = nrow(landsat), ncols = ncol(landsat), ext = extent(landsat), resolution = raster::res(landsat), vals = 0.9)))
library(abind)
landsat_mat <- do.call(abind,list(landsat_mat_list,along = 3))
hill <- demms %>%
sphere_shade()
hill <- add_overlay(hill, landsat_mat)
rgl::clear3d()
plot_3d(hillshade = hill, heightmap = dem_mat,
windowsize = c(1000, 600), zscale = zscale,
theta = 160, zoom = 0.5, phi = 35, baseshape = "circle")
library(rasterVis)
plot3D(demms,drape= biox , adjust = FALSE)
7.2.3 plot3d
spatialEco::tri()也同
library(rasterVis)
plot3D(valley)
这个可以使用R包的raster进行计算(terrain());
slope <- terrain(dem, "slope")
aspect <- terrain(dem, "aspect")
TPI <- terrain(dem, "TPI")
TRI <- terrain(dem, "TRI")
roughness <- terrain(dem, "roughness")
flowdir <- terrain(dem, "flowdir")